Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 11843 - Guessing Game / 11843.3.cpp
blob4c2533e4f03908b9ccd039dc650ba326e8f19836
1 // Wrong Answer
2 using namespace std;
3 #include <algorithm>
4 #include <iostream>
5 #include <iterator>
6 #include <numeric>
7 #include <sstream>
8 #include <fstream>
9 #include <cassert>
10 #include <climits>
11 #include <cstdlib>
12 #include <cstring>
13 #include <string>
14 #include <cstdio>
15 #include <vector>
16 #include <cmath>
17 #include <queue>
18 #include <deque>
19 #include <stack>
20 #include <list>
21 #include <map>
22 #include <set>
24 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define D(x) cout << #x " is " << x << endl
28 int memo[1005][25];
30 int myFloor(int n, int k) {
31 return n / k;
34 int myCeil(int n, int k) {
35 return (n + k - 1) / k;
38 int f(int n, int s) {
39 if (n == 0) return 0;
40 if (n == 1) return 1;
41 if (s == 1) return n;
43 if (memo[n][s] != -1) return memo[n][s];
45 int best = 1 + max( f(myFloor(n-1, 2), s-1), f(myCeil(n-1, 2), s) );
47 return memo[n][s] = best;
50 int main(){
51 int C;
52 cin >> C;
53 memset(memo, -1, sizeof memo);
54 while (C--) {
55 int n, s;
56 cin >> n >> s;
57 assert(s > 0 and n > 0);
58 int ans = f(n, s);
59 printf("%d %d = %d\n", n, s, ans);
61 return 0;